package com.etc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @Author kalista
 * @Description
 * @Date 2021/3/23  17:57
 **/
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;


    @Autowired// 服务发现
    private DiscoveryClient discoveryClient;

    private static final String url = "http://cloud-provider-paymentzk";

    @GetMapping("/consumer/payment/zk")
    public String paymentinfo(){
        String forObject = "";
        List<ServiceInstance> instances = discoveryClient.getInstances("cloud-provider-paymentzk");
//        for (ServiceInstance instance : instances) {
//            forObject  = restTemplate.getForObject(instance.getUri() + "/payment/provider/payment", String.class);
//        }
        forObject  = restTemplate.getForObject(url + "/payment/provider/payment", String.class);
        return forObject;
    }

}
